#include<bits/stdc++.h>
using namespace std;
#define int long long

int n, m;
int a[100005];

bool check(int x) {
	int cnt = 1, nowSum = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] > x)
			return false;
		if (nowSum + a[i] <= x) {
			nowSum += a[i];
		} else {
			nowSum = a[i];
			cnt++;
		}
	}
	if (cnt <= m)
		return true;
	else
		return false;
}

signed main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	int l = *max_element(a + 1, a + n + 1), r = 1e9, mid, ans = 1e9+1;

	while (l <= r) {

		mid = l + (r - l) / 2;
//		cout << l << " " << r << " " << " " << mid << " " << check(mid) << endl;
		bool returnValue = check(mid);

		if (returnValue) {
			ans = min(ans, mid);
			r = mid-1;
		} else
			l = mid+1;
	}
	cout << ans;
	return 0;
}
